; Newton-Raphson method

(define (sqrt x)
    (define (average a b)
    (/ (+ a b) 2.0))

      (define (improve guess)
    (average guess (/ x guess)))

    (define (good-enough? guess)
    (< (abs (- (square guess) x))
       0.001))

  (define (try guess)
    (display guess)
    (newline)
    (if (good-enough? guess)
    guess
    (try(improve guess))))

  (try 1))

; (define (try guess x)
;     (if (good-enough? guess x)
;     guess
;     (try (improve guess x) x)))

;  (define (improve guess x) 
;     (average guess (/ x guess)))

; (define (average a b)
;     (/ (+ a b) 2.0))

; (define (good-enough? guess x)
;     (< (abs (- (square guess) x)) 0.001))

; (define (sqrt x)
;     (try 1 x))

(sqrt 16)